﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Myotragus.Data.Metadata
{
	public class MetadataLocalizableEntityMapping : MetadataEntityMapping, ILocalizableEntityMapping
	{
		public IEnumerable<IPropertyMapping> GetLocalizableProperties(Type interfaceType)
		{
			return FindPropertiesMathing(interfaceType, IsLocalizable);
		}

		public IEnumerable<IPropertyMapping> GetNonLocalizableProperties(Type interfaceType)
		{
			return FindPropertiesMathing(interfaceType, IsNotLocalizable);
		}

		private static readonly Type TypeOfLocalizableAttribute = typeof(LocalizableAttribute);

		private static bool IsNotLocalizable(PropertyInfo property)
		{
			return !IsLocalizable(property);
		}

		private static bool IsLocalizable(PropertyInfo property)
		{
			return property.GetCustomAttributes(TypeOfLocalizableAttribute, true).Any();
		}
	}
}